package com.lp;
import java.util.List;
/**
 * 组合模式
 *
 */
public class MainClass {
	public static void main(String[] args) {
		//C盘
		Folder rootFolder = new Folder("C:");
		//temp目录
		Folder temp1Folder = new Folder("temp1");
		//temp1.txt文件
		File temp1File = new File("a1.txt");
		
		rootFolder.add(temp1Folder);
		rootFolder.add(temp1File);
		
		//temp2目录
		Folder temp2Folder = new Folder("temp2");
		File temp2File = new File("a2.txt");
		temp1Folder.add(temp2Folder);
		temp1Folder.add(temp2File);
		
		Folder temp3Folder = new Folder("temp3");
		File temp3File = new File("a3.txt");
		temp2Folder.add(temp3Folder);
		temp2Folder.add(temp3File);
		
		displayTree(rootFolder,0);
		
	}
	
	public static void displayTree(IFile rootFolder, int deep) {
		for(int i = 0; i < deep; i++) {
			System.out.print("--");
		}
		//显示自身的名称
		rootFolder.display();
		//获得子树
		List<IFile> children = rootFolder.getChild();
		//遍历子树
		for(IFile file : children) {
			if(file instanceof File) {
				for(int i = 0; i <= deep; i++) {
					System.out.print("--");
				}
				file.display();
			} else {
				displayTree(file,deep + 1);
			}
		}
	}
}
